#include <stdio.h>
#include <pthread.h>
#include "rbuf.h"
void * read_loop(void * priv);
pthread_t read_pthread;
int main(int argc, char *argv[])
{
    char buff[128];
    int i, count;
    ringbuffer r;
    ring_init(&r,128);
    pthread_create(&read_pthread, NULL, read_loop, &r);
    
    count = 0;
    while(1)
    {
        sprintf(buff,"%d-",count);
        i = ring_write(&r,buff, strlen(buff));
        if( i > 0)
            count++;
        usleep(10*1000);
    }


    ring_destroy(&r);
    return 0;
}

void * read_loop(void * priv)
{
    char buff[128];
    int count = 0;
    ringbuffer *r = (ringbuffer*)priv;
    while(1)
    {
        count = ring_read(r,buff,32);
        if(count > 0)
        {
            buff[count] = 0;
            printf("Read: %s\n",buff);
        }
        sleep(1);
    }
    return NULL;
}
